//
//  AnnounceTableViewCell.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/10/4.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "AnnounceTableViewCell.h"

@implementation AnnounceTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = TotalWhite;
        [self setMainView];
    }
    return self;
}

- (void)setMainView
{
    UIView *headView = [UIView new];
    headView.frame = CGRectMake(15, 0, SCREENWIDTH-30, 40);
    headView.backgroundColor = UIColorFromHex(0xF9F9F9);
    [self addSubview:headView];
    
    if (!self.timeLab) {
        self.timeLab = [UILabel new];
        self.timeLab.frame = CGRectMake(15, 12, 80, 17);
        self.timeLab.textColor = UIColorFromHex(0x3E3E3E);
        self.timeLab.font = FontWithSize(12);
        self.timeLab.text = @"2018-12-10";
        [headView addSubview:self.timeLab];
    }
    if (!self.deleBtn) {
        self.deleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.deleBtn.frame = CGRectMake(headView.width-65, 8, 50, 24);
        self.deleBtn.layer.cornerRadius = 10;
        self.deleBtn.layer.masksToBounds = YES;
        self.deleBtn.titleLabel.font = FontWithSize(12);
        [self.deleBtn setTitleColor:UIColorFromHex(0x3E3E3E) forState:UIControlStateNormal];
        self.deleBtn.backgroundColor = UIColorFromHex(0xF7D553);
        [self.deleBtn setTitle:@"删除" forState:UIControlStateNormal];
        [headView addSubview:self.deleBtn];
    }
    UIView *bottomView = [UIView new];
    bottomView.frame = CGRectMake(headView.left, headView.bottom, headView.width, 40);
    bottomView.backgroundColor = TotalWhite;
    bottomView.layer.borderWidth = 1;
    bottomView.layer.borderColor = UIColorFromHex(0xF3F3F3).CGColor;
    [self addSubview:bottomView];
    
    if (!self.desLab) {
        self.desLab = [UILabel new];
        self.desLab.frame = CGRectMake(15, 10, bottomView.width-30, 17);
        self.desLab.textColor = UIColorFromHex(0x3E3E3E);
        self.desLab.font = FontWithSize(12);
        self.desLab.text = @"十一旅游必备药品清单，让您放心旅游让您放";
        [bottomView addSubview:self.desLab];
    }
}

- (void)deleBtn:(UIButton*)btn
{
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:NSLocalizedString(@"确定删除h公告？", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"取消", nil) otherButtonTitles:NSLocalizedString(@"确定", nil), nil];
    [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        if ([self.delegate respondsToSelector:@selector(deleteThisAnnounce:and:)])
        {
            [self.delegate deleteThisAnnounce:self.model.id and:self.indexPath];
        }
    }
}

- (void)getData:(AnnounceModel *)model
{
    self.model = model;
    self.timeLab.text = [NSString stringWithFormat:@"%@",model.date];
    self.desLab.text = [NSString stringWithFormat:@"%@",model.title];
      [self.deleBtn addTarget:self action:@selector(deleBtn:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
